<?php
include('../koneksi.php');

function masuk($user, $pass){
	$q = "SELECT user FROM admin WHERE user='".$user."' and password='".$pass."'";	
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");
	$data= mysql_fetch_row($hasil);
	if($data>=1){
	return TRUE;
	}
}

function kategori($id=''){
	$q = "SELECT id_kategori, kategori FROM kategori";	
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");
	while($isi = mysql_fetch_assoc($hasil)){
		$selected='';
		if($id==$isi['id_kategori']){
			$selected='selected=selected';
		}
		echo "<option value='".$isi['id_kategori']."' ".$selected.">".$isi['kategori']."</option>";
	}
}
function keluar(){
	session_destroy();
}
function tambah($judul, $detail, $gambar, $kategori, $status){
	$q = "INSERT INTO berita (judul, detail, waktu_post, gambar, status, id_kategori) VALUES ('".$judul."', '".$detail."', '".date('Y-m-d H:i:s')."', '".$gambar."', ".$status.", ".$kategori.")";	
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");
	
	echo "<script>
			window.location = '../admin/pengaturan_berita.php';
	</script>";
}
function ubah($judul, $detail, $gambar, $kategori, $status, $id){
	$q = "UPDATE berita SET judul='".$judul."', detail='".$detail."', waktu_post='".date('Y-m-d H:i:s')."', gambar='".$gambar."', status=".$status.", id_kategori=".$kategori." WHERE id_berita=".$id;	
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");
	
	echo "<script>
			alert('Data Berhasil Berubah');
			window.location = '../admin/pengaturan_berita.php';
	</script>";
}
function hapus($id){	
	$q = "DELETE FROM berita WHERE `id_berita`=".$id;	
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");	
	echo "Data berhasil didelete.";
}
function kategori_tambah($kategori){
	$q = "INSERT INTO kategori (kategori) VALUES ('".$kategori."')";	
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");
	
	echo "<script>
			window.location = '../admin/kategori_tampil.php';
	</script>";
}
function kategori_ubah($id, $kategori){
	$q = "UPDATE kategori SET kategori = '".$kategori."' WHERE id_kategori=".$id;	
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");
	
	echo "<script>
			window.location = '../admin/kategori_tampil.php';
	</script>";
}
function tampil_ubah($id){
	$q = "select id_berita, judul, detail, id_kategori, status, gambar from berita WHERE id_berita=".$id;
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");
	return $hasil;
}
function kategori_hapus($id){
	$q = "DELETE FROM kategori WHERE id_kategori=".$id;	
	$hasil= mysql_query($q) or exit("Error query : <b>".$q."</b>.");	
	echo "Data berhasil didelete.";
}
?>